//
//  EpointDatePickerAlertView.m
//  iphone.mobileoa
//
//  Created by 李亚春 on 13-6-21.
//  Copyright (c) 2013年 Epoint. All rights reserved.
//

#import "EpointDatePickerAlertView.h"
#import "DateUtil.h"

@interface EpointDatePickerAlertView()
{
}
@end

@implementation EpointDatePickerAlertView

- (id)init
{
    CGFloat frame_height = [[UIScreen mainScreen]bounds].size.height-64;
    
    CGFloat midy = frame_height/2-380/2;
    self = [super initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen]bounds].size.width, frame_height)];
    if (self) {
        [self setBackgroundColor:[UIColor colorWithRed:191/255.0f green:191/255.0f blue:191/255.0f alpha:0.8f]];
        
        
        UIView *alertFrame = [[UIView alloc]initWithFrame:CGRectMake(0, midy, 320, 304)];
        [alertFrame setBackgroundColor:[UIColor grayColor]];
        
        self.p = [[UIDatePicker alloc]initWithFrame:CGRectMake(0, 44, 260, 216)];
        
        [alertFrame addSubview:self.p];
        
        UILabel *lbTitle = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 280, 44)];
        
        [lbTitle setTextColor:[UIColor whiteColor]];
        [lbTitle setFont:[UIFont boldSystemFontOfSize:16]];
        [lbTitle setBackgroundColor:[UIColor clearColor]];
        [lbTitle setText:@"日期选择"];
        [alertFrame addSubview:lbTitle];
        [lbTitle release];
        
        UIButton *btCancel = [[UIButton alloc]initWithFrame:CGRectMake(0,260, 160, 44)];

        [btCancel setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [btCancel setBackgroundColor:[UIColor whiteColor]];
        [btCancel setBackgroundImage:[UIImage imageNamed:@"topbar"] forState:UIControlStateHighlighted];
        btCancel.titleLabel.text = @"取消";
        [btCancel setTitle:@"取消" forState:UIControlStateNormal];
        [btCancel addTarget:self action:@selector(cancelAction) forControlEvents:UIControlEventTouchUpInside];
        [alertFrame addSubview:btCancel];
        [btCancel release];
        
        UIButton *btOK = [[UIButton alloc]initWithFrame:CGRectMake(160,260, 160, 44)];
        [btOK addTarget:self action:@selector(OKAction) forControlEvents:UIControlEventTouchUpInside];
        [btOK setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [btOK.titleLabel setTextColor:[UIColor blackColor]];
        [btOK setBackgroundImage:[UIImage imageNamed:@"topbar"] forState:UIControlStateHighlighted];
        [btOK setBackgroundColor:[UIColor whiteColor]];
        btOK.titleLabel.text = @"确定";
        [btOK setTitle:@"确定" forState:UIControlStateNormal];
        [alertFrame addSubview:btOK];
        [btOK release];
        
        [self addSubview:alertFrame];
        [alertFrame release];
    }
    return self;
}

-(void)OKAction
{
    [self removeFromSuperview];
    [self.delegate epointDatePickerSelected:self];
    NSLog(@"%@",[DateUtil getTimeStr:self.p.date]);
}

-(void)cancelAction
{
    [self removeFromSuperview];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
